package synchronize.synchronize007;

public class RunThread extends Thread {
    /**
     * volatile:多线程可见
     */
    private boolean isRunning = true;

    private void setRunning(boolean isRunning) {
        this.isRunning = isRunning;
    }

    public void run() {
        System.out.print("进入run方法");
        while (isRunning == true) {

        }
        System.out.print("线 程终止");
    }

    public static void main(String[] args) throws InterruptedException {
        RunThread rt = new RunThread();
        rt.start();
        Thread.sleep(30000);
        rt.setRunning(false);
        System.out.print("isRunning的值已经被设置了false");
        Thread.sleep(1000);
        System.out.print(rt.isRunning);
    }
}
